<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    const restoreIpAddresses = (s) => {
      let result = []
      const handler = (s, temp, result) => {
        if(temp.length === 4) {
          if(!s) result.push(temp.join('.'))
          return
        }
        if(!s) return
        for (let i = 0; i < s.length && i < 3; i++) {
          let str = ''
          str += s.substr(0, i + 1)
          if(Number(str) > 255) return
          if(/^0[0-9]+/.test(str)) return
          let clone = [...temp]
          clone.push(str)
          handler(s.slice(i + 1), clone, result)
        }
      }
      handler(s, [], result)
      return result
    }
    console.log(restoreIpAddresses('25525511135'))
  </script>
</body>
</html>